package com.ch;

import com.ch.domain.Person;

/**
 * @author chenhong
 * @version 1.0.0
 * @ClassName reflection.java
 * @Description TODO
 * @createTime 2020年12月21日 20:43:00
 */
public class reflection {

    public static void main(String[] args) throws ClassNotFoundException {

        //每个类只能有一个
        Class c1 = Class.forName("com.ch.domain.Student");
        Class c2 = Class.forName("com.ch.domain.Student");
        Class c3 = com.ch.domain.Student.class;
        System.out.println(c1.equals(c2));
        System.out.println(c1.equals(c3));
        //获取父类
        System.out.println(c1.getSuperclass());


        //只要元素类型和维度相等，就是同一个class
        int []a = new int[10];
        int []b = new int[100];
        System.out.println(a.getClass().hashCode() == b.getClass().hashCode());

        //系统类加载器的父类(AppClassLoader)为 --》 扩展类加载器(ExtClassLoader)  --》根加载器(null 无法直接获取到)
        ClassLoader classLoader =  ClassLoader.getSystemClassLoader();
        ClassLoader classLoaderParent =  ClassLoader.getSystemClassLoader().getParent();
        ClassLoader classLoaderAncestor  =  ClassLoader.getSystemClassLoader().getParent().getParent();
        System.out.println(classLoader);
        System.out.println(classLoaderParent);
        System.out.println(classLoaderAncestor);

        //测试一下类加载器Object为根加载器加载 而自己定义的类由系统加载器加载
        ClassLoader loader = Class.forName("java.lang.Object").getClassLoader();
        System.out.println(loader);
        ClassLoader loader1 = Class.forName("com.ch.domain.Person").getClassLoader();
        System.out.println(loader1);

    }
}
